<!--_meta 作为公共模版分离出去-->
<include file='public/_meta'>
<!--/meta 作为公共模版分离出去-->
<title>异常离线</title>
</head>
<body>

<nav class="breadcrumb"><i class="Hui-iconfont">&#xe67f;</i> 首页 <span class="c-gray en">&gt;</span> 异常离线 <span class="c-gray en">&gt;</span> 异常离线 <a class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px" href="javascript:location.replace(location.href);" title="刷新" ><i class="Hui-iconfont">&#xe68f;</i></a></nav>
<div class="page-container">
	<div class="text-c" id="search_down"> 添加时间:
		<input type="text" onfocus="WdatePicker({ maxDate:'#F{ $dp.$D(\'datemax\')||\'%y-%M-%d\' }' })" id="datemin" class="input-text Wdate" style="width:120px;">
		-
		<input type="text" onfocus="WdatePicker({ minDate:'#F{ $dp.$D(\'datemin\') }',maxDate:'%y-%M-%d' })" id="datemax" class="input-text Wdate" style="width:120px;">
		<input type="text" class="input-text" style="width:250px" placeholder="车牌、车架、智能设备号..." id="search_inpute" >
        <span class="select-box" style="width:100px;">
                    <select class="select" id="brand_id">
                        <option value="" style="color: #429842;">品牌类型</option>
                        <foreach $brand as $value>
                        <option value="{$value.id}">{$value.name}</option>
                        </foreach>                        
                    </select>
                </span>
        <span class="select-box" style="width:100px;">
                    <select class="select" id="agency_id">
                        <option value="" style="color: #429842;">加盟商</option>
                        <foreach $agency as $value>
                        <option value="{$value.id}">{$value.name}</option>
                        </foreach>
                        
                    </select>
        </span>
        <span class="select-box" style="width:96px;">
            <select class="select" name="supplier_no" id="supplier_no" size="1">
                <option value="" style="color: #429842;">车机型号</option>
                <option value="1376920001">W</option>
                 <option value="1376920003">S-IOT</option>
                <option value="1376920002">S</option>
            </select>
        </span>
		<button type="submit" class="btn btn-success radius" id="search_btn"><i class="Hui-iconfont">&#xe665;</i> 搜索</button> 
	</div>
    <div class="cl pd-5 bg-1 bk-gray mt-20"> <span class="l"><a class="btn btn-warning radius" onclick="excel_data_out('导出excel','{:url('index/excell/off')}','','310')" href="javascript:;"><i class="Hui-iconfont">&#xe641;</i> 导出EXCEL</a></span></div>
	<div class="mt-20">
	<table class="table table-border table-bordered table-hover table-bg table-sort">
		<thead>
			<tr class="text-c">
				<th>车牌号</th>
				<th>车架号</th>
                <th>品牌名称</th>
                <th>加盟商</th>
                <th>车机号</th>
				<!-- <th width="160">卡号</th>
				<th width="180">卡序列号</th> -->
                <th>车机型号</th>
                <th>离线时间</th>
				<th>车机时间</th>
				<th>记录时间</th>
				<th>操作</th>
			</tr>
		</thead>
		<tbody>
			
		</tbody>
	</table>
	</div>
</div>
<!--_footer 作为公共模版分离出去-->
<include file='public/_footer'>
<!--/_footer 作为公共模版分离出去-->

<!--请在下方写此页面业务相关的脚本-->
<script type="text/javascript" src="__PUBLIC__/lib/My97DatePicker/4.8/WdatePicker.js"></script> 
<script type="text/javascript" src="__PUBLIC__/lib/datatables/1.10.0/jquery.dataTables.min.js"></script> 
<script type="text/javascript" src="__PUBLIC__/lib/laypage/1.2/laypage.js"></script>
<script type="text/javascript">
$(function(){
    var table = $('.table-sort').DataTable({
        "aaSorting": [[ 0, "desc" ]],//默认第几个排序
        // "bStateSave": true,//状态保存
         searching: false,
        "aoColumnDefs": [
          //{"bVisible": false, "aTargets": [ 3 ]} //控制列的隐藏显示
          {"orderable":false,"aTargets":[0,1,2,3,4,5,6,7,8,9]}// 制定列不参与排序
        ],
        "bProcessing" : true, //开启读取服务器数据时显示正在加载中……特别是大数据量的时候，开启此功能比较好  
        "bServerSide" : true,//服务器处理分页，默认是false，需要服务器处理，必须true  
        "ajax": {
            "url": "{:url('index/off/abnormal')}",
            "type": "POST"
        },
        displayLength: 10,
        columns: [
        { data: 'car_sn' },
        { data: 'car_unique_id' },
        { render:function (data, type, row, meta) {
                if(row.brand){
                    data = row.brand.name
                }else{
                    data = '未知';
                }
                return data;
            } 
        },
        { render:function (data, type, row, meta) {
                if(row.agency){
                    data = row.agency.name
                }else{
                    data = '未知';
                }
                return data;
            } 
        },
        { data: 'equipment_id'},
        /*{ data: 'cardcode'},
        { data: 'sim_id'},*/
        { data:'supplier_no',render:data=>{
                switch (data) {
                    case '1376920002':
                    data = 'S';     
                        break;
                    case '1376920001':
                    data = 'W';     
                        break;
                        case '1376920003':
                    data = 'S-IOT';     
                        break;
                    default:
                    data = '未知';   
                        break;
                }
               
                return data;
            } 
        },
        { render:function (data, type, row, meta) {
            if(row.machine_report_time){

                var now = new Date().getTime();
                var value = (now - row.machine_report_time) / 1000;

                let day = parseInt(value / 86400);
                let hour = parseInt((value - day * 86400) / 3600);
                let month = parseInt(day/30);
                if(month>=1){
                    return '<span class="label label-danger radius">'+month+'个月'+'<span>';
                }else if(day > 0){
                    return '<span class="label label-danger radius">'+day+'天'+'<span>';
                }else if(hour > 0){
                    return hour+'小时';
                }

            }else{
                return '未知';
            }
        }},
        { render:function (data, type, row, meta) {
                if(row.machine_report_time){
                    if(row.machine_report_time!=null && row.machine_report_time!=0){
                        let formatTimeS = new Date(row.machine_report_time);
                        let _year = formatTimeS.getFullYear();
                        let _month = (formatTimeS.getMonth()+1< 10 ? '0'+(formatTimeS.getMonth()+1) : formatTimeS.getMonth()+1);
                        let _date = formatTimeS.getDate()<10 ? '0'+formatTimeS.getDate():formatTimeS.getDate();
                        let _hour = formatTimeS.getHours()<10 ? '0'+formatTimeS.getHours() : formatTimeS.getHours();
                        let _minute = formatTimeS.getMinutes()<10?'0'+formatTimeS.getMinutes():formatTimeS.getMinutes();
                        let _second = formatTimeS.getSeconds()<10?'0'+formatTimeS.getSeconds():formatTimeS.getSeconds();
                        return _year+'-'+_month+'-'+_date+' '+_hour+':'+_minute+':'+_second;
                        
                    }else{
                       data = '未知'; 
                    }
                }else{
                    data = '未知';
                }
                return data;
            } 
        },
        { data: 'create_time' },
        { className: "td-manage",data: '',render: function (data, type, row, meta) {
        	var str = '';
	            str += '<a title="编辑" href="javascript:;" onclick="edit(';
	            str += "'编辑',";
	            str += "'{:url('index/off/edit')}?id="+row['id']+"'";
	            str += ",'',650)\"";
	            str += 'class="ml-5" style="text-decoration:none"><i class="Hui-iconfont">&#xe6df;</i></a>';
	            
	        	return str;
                                
        	}
        },

        ],
         
    });

    $("#search_btn").click(res=>{
        request();
    });

    $("#search_down").keydown(event=>{
           if (event.which == 13){
                request();
           }
    })

    function request() {
        table.settings()[0].ajax.data = {
            'datemin':$('#datemin').val(),
            'datemax':$('#datemax').val(),
            'brand_id':$('#brand_id').val(),
            'agency_id':$('#agency_id').val(),
            'supplier_no':$('#supplier_no').val(),
            'search_inpute':$('#search_inpute').val(),
        };
        table.ajax.reload();
    }

});

function autoTime(num) {
    if (!num) {
        return ''
    }
    var now = new Date().getTime();
    var value = (now - num) / 1000;
    var str = '';

    let day = parseInt(value / 86400);
    let hour = parseInt((value - day * 86400) / 3600);
    if(day > 0){
        return day + '天';
    }else if(hour > 0){
        return hour + '小时';
    }
    
    return false
}

function edit(title,url,w,h){
	layer_show(title,url,w,h);
}

/*导入表格数据*/
function excel_data_add(title,url,w,h){
    layer_show(title,url,w,h);
}

/*导出*/
function excel_data_out(title,url,w,h) {
    
    layer.confirm('<p class="c-warning">可以选择搜索条件导出</p>',function(index){
     // top.location.href = url;
        let datemin = $('#datemin').val();
        let datemax = $('#datemax').val();
        let brand_id = $('#brand_id').val();
        let agency_id = $('#agency_id').val();
        let supplier_no = $('#supplier_no').val();
        let type = $('#type').val();
        let search_inpute = $('#search_inpute').val();

        window.location.href = url+'?'+'datemin='+datemin+'&datemax='+datemax+'&brand_id='+brand_id+'&agency_id='+agency_id+'&supplier_no='+supplier_no+'&type='+type+'&search_inpute='+search_inpute;

            layer.msg('导出成功,正在下载', {icon: 1});
                
        
        });

}
</script> 
</body>
</html>